#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<unordered_map>
#include<string>
#include<queue>

using namespace std;
const int N = 6;

int n;
string A, B;
string a[N], b[N];

int extend_tran(queue<string>& qa, unordered_map<string, int>& ua, unordered_map<string, int>& ub, string a[], string b[]) {
	string t = qa.front();
	qa.pop();

	for (int i = 0; i < t.size(); i++) {
		for (int j = 0; j < n; j++) {
			if (t.substr(i, a[j].size()) == a[j]) {
				string state = t.substr(0, i) + b[j] + t.substr(i + a[j].size());

				if (ua.count(state)) continue;
				if (ub.count(state)) return ua[t] + 1 + ub[state];
				if (ua[t] + 1 > 10) continue;

				qa.push(state);
				ua[state] = ua[t] + 1;
			}
		}
	}

	return 11;
}


int bfs(string& A, string& B) {
	queue<string> qa;
	queue<string> qb;
	unordered_map<string, int> ua;
	unordered_map<string, int> ub;

	qa.push(A);
	ua[A] = 0;
	qb.push(B);
	ub[B] = 0;

	while (!qa.empty() && !qb.empty()) {
		int tt = 0;
		if (qa.size() < qb.size()) {
			tt = extend_tran(qa, ua, ub, a, b);
		}
		else {
			tt = extend_tran(qb, ub, ua, b, a);
		}

		if (tt <= 10) return tt;
	}

	return 11;
}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> A >> B;
	if(A == B){
	    cout << 0;
	    return 0;
	}
	while (cin >> a[n] >> b[n]) n++;

	int res = bfs(A, B);

	if (res <= 10) {
		cout << res << endl;
	}
	else {
		cout << "NO ANSWER!" << endl;
	}
	return 0;
}